﻿

using System;
using AutoMapper;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization;

using Oliving.Edge.AuthHelper;
using Oliving.Edge.Model;
using Oliving.Edge.Model.Models;
using Oliving.Edge.IServices;
using Oliving.Edge.Model.Dto;
using System.Linq.Expressions;
using Oliving.Edge.Common.Extensions;


namespace Oliving.Edge.Controllers.BaseTest
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestLogController : OlivingControll
    {

        IMapper _mapper;

        private readonly ILogger<TestLogController> _logger;


        public TestLogController(
                IHttpContextAccessor accessor, PermissionRequirement requirement,
                IMapper mapper, ILogger<TestLogController> logger
            ) : base(accessor, requirement)
        {
            _logger = logger;
            _mapper = mapper;

        }



        /// <summary>
        /// Nlog 记录日志测试（记事本、数据库）
        /// 		<!--日志级别 Trace|Debug|Info|Warn|Error|Fatal-->
        ///         <!--日志级别 跟踪|调试|信息|警告|错误|致命-->
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/GetLogTrace")]
        public async Task<MessageModel<string>> GetLogTrace(int id = 0)
        {
            _logger.LogTrace("GetLogTrace........................................." + DateTime.Now.ToString());
            var data = new MessageModel<string>();
            return data;
        }


        /// <summary>
        /// Nlog 记录日志测试（记事本、数据库）
        /// 		<!--日志级别 Trace|Debug|Info|Warn|Error|Fatal-->
        ///         <!--日志级别 跟踪|调试|信息|警告|错误|致命-->
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/GetLogDebug")]
        public async Task<MessageModel<string>> GetLogDebug(int id = 0)
        {
            _logger.LogDebug("GetLogDebug........................................." + DateTime.Now.ToString());
            var data = new MessageModel<string>();
            return data;
        }


        /// <summary>
        /// Nlog 记录日志测试（记事本、数据库）
        /// 		<!--日志级别 Trace|Debug|Info|Warn|Error|Fatal-->
        ///         <!--日志级别 跟踪|调试|信息|警告|错误|致命-->
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/GetLogInformation")]
        public async Task<MessageModel<string>> GetLogInformation(int id = 0)
        {
            _logger.LogInformation("GetLogInformation........................................." + DateTime.Now.ToString());
            var data = new MessageModel<string>();
            return data;
        }

        /// <summary>
        /// Nlog 记录日志测试（记事本、数据库）
        /// 		<!--日志级别 Trace|Debug|Info|Warn|Error|Fatal-->
        ///         <!--日志级别 跟踪|调试|信息|警告|错误|致命-->
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/GetLogWarning")]
        public async Task<MessageModel<string>> GetLogWarning(int id = 0)
        {
            _logger.LogWarning("GetLogWarning........................................." + DateTime.Now.ToString());
            var data = new MessageModel<string>();
            return data;
        }




        /// <summary>
        /// Nlog 记录日志测试（记事本、数据库）
        /// 		<!--日志级别 Trace|Debug|Info|Warn|Error|Fatal-->
        ///         <!--日志级别 跟踪|调试|信息|警告|错误|致命-->
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/GetLogError")]
        public async Task<MessageModel<string>> GetLogError(int id = 0)
        {
            _logger.LogError("GetLogError........................................." + DateTime.Now.ToString());
            var data = new MessageModel<string>();
            return data;
        }


        /// <summary>
        /// Nlog 记录日志测试（记事本、数据库）
        /// 		<!--日志级别 Trace|Debug|Info|Warn|Error|Fatal-->
        ///         <!--日志级别 跟踪|调试|信息|警告|错误|致命-->
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/LogCritical")]
        public async Task<MessageModel<string>> LogCritical(int id = 0)
        {
            _logger.LogCritical("LogCritical........................................." + DateTime.Now.ToString());
            var data = new MessageModel<string>();
            return data;
        }






        /// <summary>
        ///  抛出异常，记录日志。 在GlobalExceptionsFilter 中捕获异常
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        [Route("/api/[controller]/GetException")]
        public async Task<MessageModel<string>> GetException(int id = 0)
        {

            throw new Exception("edge 抛出异常=>" + DateTime.Now);


            var data = new MessageModel<string>();

            return data;
        }



    }
}
